#pragma once
#include "stdafx.h"
#include "ButtonUIEx.h"
#include "RotButton.h"
#include "AnimaButton.h"
#include "ControlEx.h"
#include "FlowButton.h"
#include "LineFlowButton.h"
#include "SolarThermalShow.h"
#include "EnergyFlowManage.h"

class CSolarThermalWndUI : public CContainerUI
{
	DECLARE_DUICONTROL(CSolarThermalWndUI)
public:
	CSolarThermalWndUI()
	{
		CDialogBuilder builder;
		CContainerUI* pComputerExamine = static_cast<CContainerUI*>(builder.Create(_T("solarthermal.xml"), (UINT)0));
		if (pComputerExamine) {
			this->Add(pComputerExamine);
		}
		else {
			this->RemoveAll();
			return;
		}
	}
};

//class CDialogBuilderCallbackEx : public IDialogBuilderCallback
//{
//public:
//	CControlUI* CreateControl(LPCTSTR pstrClass)
//	{
//		if (_tcscmp(pstrClass, _T("SolarThermalWnd")) == 0) return new CSolarThermalWndUI;
//		return NULL;
//	}
//};

class SolarThermalFramWnd
{
public:
	SolarThermalFramWnd(CPaintManagerUI* pm)
	{
		m_pm = pm;
	}

	void Init();

	void InitSteamFlow();
	void InitSaltFlow();
	void InitElectricityFlow();
	void InitFlowChain();
	void ActSteamFlow();
	void ActSaltFlow();
	void ActElectricityFlow();

	void InitCodeSaltTankToHeatFlow();
	void InitCodeSaltPumptoCSTFlow();
	void InitHotSaltPumptoTankFlow();
	void InitHotSaltPumptoSteamGenFlow();
	void InitUseSteamToDynamoFlow();
	void InitLoopTheSteamFlow();
	void InitFlowManualAnimChain();
	void ActCodeSaltTankToHeatFlow();
	void ActCodeSaltPumptoCSTFlow();
	void ActHotSaltPumptoTankFlow();
	void ActHotSaltPumptoSteamGenFlow();
	void ActUseSteamToDynamoFlow();
	void ActLoopTheSteamFlow();

	void StartFlow();
	void ManualFlow();
	void StopFlow();

	BOOL OnLClick(CControlUI *pControl);

private:
	CPaintManagerUI* m_pm;

	/// ****************************************
	/// solar_tower
	CGifControlUI *m_pSolarTower;
	CLineFlowButtonUI *m_pPipeSolarLeftIn;
	CLineFlowButtonUI *m_pPipeSolarRightOut;
	CLineFlowButtonUI *m_pPipeSolarIn;
	CLineFlowButtonUI *m_pPipeSolarOut;

	/// hot_pump
	CRotButtonUI *m_pHotPump;
	CLineFlowButtonUI *m_pPipeHotPumpIn;
	CLineFlowButtonUI *m_pPipeHotPumpOut;

	/// cold_pump
	CRotButtonUI *m_pColdPump;
	CLineFlowButtonUI *m_pPipeColdPumpIn;
	CLineFlowButtonUI *m_pPipeColdPumpOut;

	/// hot_pump_2repo
	CRotButtonUI *m_pHotPump2Repo;
	CLineFlowButtonUI *m_pPipeHotPump2RepoIn;
	CLineFlowButtonUI *m_pPipeHotPump2RepoOut;

	/// water_pump
	CRotButtonUI *m_pWaterPump;
	CLineFlowButtonUI *m_pWaterPumpDown;
	CLineFlowButtonUI *m_pWaterPumpUp;
	CLineFlowButtonUI *m_pWaterPumpIn;
	CLineFlowButtonUI *m_pWaterPumpOut;

	/// coldsalt_repo
	CSTTankUI *m_pColdRepo;
	CLineFlowButtonUI *m_pColdRepoIn;
	CLineFlowButtonUI *m_pColdRepoOut;
	CLineFlowButtonUI *m_pColdSaltLoop;

	/// hotsalt_repo
	CSTTankUI *m_pHotRepo;
	CLineFlowButtonUI *m_pHotRepoIn;
	CLineFlowButtonUI *m_pHotRepoOut;

	/// steam_gener
	CGifControlUI *m_pSteamGener;
	CLineFlowButtonUI *m_pSteamGenSaltIn;
	CLineFlowButtonUI *m_pSteamGenSaltOut;
	CLineFlowButtonUI *m_pSteamGenWaterIn;
	CLineFlowButtonUI *m_pSteamGenSteamOut;

	/// dynamo
	CGifControlUI *m_pDynamo;
	CLineFlowButtonUI *m_pDynamoSteamIn;
	CLineFlowButtonUI *m_pDynamoWaterOut;
	CLineFlowButtonUI *m_pElectricOut;

	/// ac_out
	CGifControlUI *m_pAcNet;

	/// condenser
	CGifControlUI *m_pCondenser;
	CLineFlowButtonUI *m_pCondenserSteamIn;
	CLineFlowButtonUI *m_pCondenserWaterOut;

	/// deaerator
	CGifControlUI *m_pDeaerator;
	CLineFlowButtonUI *m_pDeaeratorWaterIn;
	CLineFlowButtonUI *m_pDeaeratorWaterout;

	/// to act
	CButtonUI *m_pToAct;
	CButtonUI *m_pToPause;
	CButtonUI *m_pToStop;

	/// to show
	CGifControlUI *m_pToShow;

	/// flow loop for auto anima
	vector<SolarThermalShow *> vecSaltFlowLoop;
	vector<SolarThermalShow *> vecSteamFlowLoop;
	vector<SolarThermalShow *> vecElectricityFlowLoop;
	vector<CDuiString> vecAnimaImg;
	vector<CDuiString> vecAnimaImg_SolarTower;
	BOOL	m_bIsManualFlowInit = FALSE;
	BOOL	m_bIsAutoFlowInit = FALSE;

	/// flow loop for manual anima
	vector<SolarThermalShow *> vecCodeSaltTankToHeat;
	vector<SolarThermalShow *> vecCodeSaltPumptoCST;
	vector<SolarThermalShow *> vecHotSaltPumptoTank;
	vector<SolarThermalShow *> vecHotSaltPumptoSteamGen;
	vector<SolarThermalShow *> vecUseSteamToDynamo;
	vector<SolarThermalShow *> vecLoopTheSteam;

	//// show mode
	enum
	{
		SHOW_MODE_AUTO = 0,
		SHOW_MODE_MANUAL,
		SHOW_MODE_NUM
	} m_enShowMode = SHOW_MODE_AUTO;


};
